﻿class BaseGrid implements IGrid {
    Width: number;
    Height: number;
    NrOfIteration: number;

    GetCellRaw(x: number, y: number) { return null; }
    GetCell(x: number, y: number) { return null; }

    GetNrOfCells() {
        return this.Width * this.Height;
    }

    GetNrOfCellsOfState(state: CellState): number {
        var retVal: number = 0;
        for (var x = 0; x < this.Width; x++) {
            for (var y = 0; y < this.Height; y++) {
                if (this.GetCellRaw(x, y).State == state)
                    retVal++;
            }
        }
        return retVal;
    }

    GetNrOfNeighbourCellsOfState(state: CellState, x: number, y:number) {
        var retVal: number = 0;
        for (var i = x - 1; i <= x + 1; i++) {
            for (var j = y - 1; j <= y + 1; j++) {
                if ((i != x) || (j != y))
                    if (this.GetCell(i, j).State == state)
                        retVal++;
            }
        }
        return retVal;
    }

    GenerateContent(drawArea:IDrawArea) {
        for (var x = 0; x < this.Width; x++) {
            for (var y = 0; y < this.Height; y++) {
                this.GetCellRaw(x, y).CalculateNextState();
            }
        }

        for (var x = 0; x < this.Width; x++) {
            for (var y = 0; y < this.Height; y++) {
                this.GetCellRaw(x, y).TakeOverNextState();
            }
        }

        this.NrOfIteration++;
    }


}
 